package com.camps.sdk.decrypt;

import com.camps.sdk.common.Constants;
import com.camps.sdk.entity.DeviceUpMessage;
import com.camps.sdk.entity.WifiMac;

/**
 * @Author ldaoliang
 * @Date create in 15:58 2021/9/1
 * @Description
 */
public class AnalyzeWifiMac implements AnalyticalData {
    @Override
    public DeviceUpMessage parseData(String originalData) {
        // *WT,800115470000876,WIFIMAC,152715,106,0,81,0,5,d4:ee:07:15:39:fe,-74,28:94:0f:f9:c4:85,-80,a0:63:91:6a:d4:ba,-85,1c:78:39:0b:3d:dd,-87,06:1b:6d:c8:3f:85,-89,090621,FFFFFFDF#
        //解密
        String[] split = parseCommand(originalData);
        String imei = split[1];
        String commandNumber = split[3];
        String gsm = split[4];
        String gps = split[5];
        String bat = split[6];
        String step = split[7];   // 步数
        String wifiNum = split[8];
        int num = Integer.parseInt(wifiNum);
        String date=split[split.length-2];
        String wifiInfo = "";
        //wifi信息:mac地址,信号强度,wifi名称|mac地址,信号强度,wifi名称
        for (int i = 0; i < num; i++) {
            if(wifiInfo!=null && !wifiInfo.equals("")){
                wifiInfo =wifiInfo.concat("|");
            }
            wifiInfo =wifiInfo.concat(split[9 + 2*i]).concat(",").concat(split[10 + 2*i]);
        }
        WifiMac wifiMac = new WifiMac();
        wifiMac.setImei(imei);
        wifiMac.setBattery(Integer.parseInt(bat));
        wifiMac.setCommandNumber(commandNumber);
        wifiMac.setDeviceTime(commandNumber);
        wifiMac.setWifiInfo(wifiInfo);
        wifiMac.setStepNum(Integer.parseInt(step));
        wifiMac.setDeviceDate(date);
        wifiMac.setGps(gps);
        wifiMac.setGsm(gsm);
        return structureMessage(Constants.UPLOAD,Constants.UP_WIFI_INFO,false,"",wifiMac);
    }
}
